package cn.life.business.project.controller;

import cn.life.business.project.entity.po.ProjectPo;
import cn.life.business.project.service.ProjectService;
import cn.life.common.entity.model.CMessage;
import cn.life.common.entity.model.MyUser;
import cn.life.common.entity.model.MyUserInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * @Description:    项目Controller
 *
 * @Author 李佳明
 * @Date 2018-07-24 15:56
 */
@RestController
@RequestMapping("project")
public class ProjectController {

    @Autowired
    private ProjectService projectService;

    /**
     * @Description:    增加项目
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("add")
    public CMessage addProject(@RequestBody ProjectPo projectPo, @MyUser MyUserInfo myUserInfo) throws IllegalAccessException {
        setOprData(projectPo,myUserInfo);
        return projectService.addProject(projectPo);
    };

    /**
     * @Description:    增加项目
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("update")
    public CMessage updateProject(@RequestBody ProjectPo projectPo){
        return  projectService.updateProject(projectPo);
    };

    /**
     * @Description:    增加项目
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("delete")
    public CMessage deleteProject(@RequestBody ProjectPo projectPo){
        return  projectService.deleteProject(projectPo);
    };

    /**
     * @Description:    查询项目列表
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("queryList")
    public CMessage queryProjectList(@MyUser MyUserInfo myUserInfo,@RequestBody ProjectPo projectPo){
        projectPo.setFactoryId(myUserInfo.getFactoryId());
        return projectService.queryProjectList(projectPo);
    };

    /**
     * @Description:    查询项目详情
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("queryDetail")
    public CMessage queryProjectDetail(@RequestBody ProjectPo projectPo){
        return projectService.queryProjectDetail(projectPo);
    };

    /**
     * @Description:    查询项目连带详情信息
     *
     * @return:
     *
     * @Author 李佳明
     * @Date 2018/7/19 0019 下午 1:09
     */
    @PostMapping("queryDetails")
    public CMessage queryProjectDetails(@RequestBody ProjectPo projectPo){
        return projectService.queryProjectDetails(projectPo);
    };


    public void setOprData(ProjectPo projectPo,MyUserInfo myUserInfo){
        projectPo.setFactoryId(myUserInfo.getFactoryId());
        projectPo.setFactoryName(myUserInfo.getFactoryName());
        projectPo.setOprUserId(myUserInfo.getUserId());
        projectPo.setOprUserName(myUserInfo.getUserName());
        projectPo.setOprDate(new Date());
    }
}
